﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace web.Controllers
{
    public class TestController : Controller
    {
        // 花名册页面
        public ActionResult Index()
        {
            return View();
        }
        // 添加用户
        public ActionResult addPersonView()
        {
            return View();
        }
        //登录
        public ActionResult Login()
        {
            return View();
        }
        //管理员界面
        public ActionResult adminView()
        {
            return View();
        }
        //薪水界面
        public ActionResult MoneyView()
        {
            return View();
        }
        //薪水报表
        public ActionResult MoneyInfoView()
        {
            return View();
        }

        //计算薪水
        public JsonResult get_salary(int staffid, int m_workhours, float m_insurance, float m_sum)
        {
            float salary = SqlDbHelper.salary(staffid, m_workhours, m_insurance, m_sum);
            return Json(salary);
        }

        //保存薪水
        public JsonResult save_salary(int staffid, int m_workhours, float m_insurance, float m_sum)
        {
            int a = SqlDbHelper.salary_save(staffid, m_workhours, m_insurance, m_sum);

            if (a == 1)
                return Json("添加成功");
            return Json("添加成功");
        }

        //登录
        public JsonResult logon(string username, string password, string admin)
        {
            bool isOK = SqlDbHelper.toLog(username, password, admin);
            if (!isOK)
                return Json("error");
            return Json("success");
        }

        //得到所有职工信息
        public JsonResult getAllStaff()
        {
            List<Staff> data = SqlDbHelper.getAllStaff();
            return Json(data);
        }
        //得到所有工资信息
        public JsonResult getMoneyInfo()
        {
            List<allMoney> data = SqlDbHelper.getAllMoney();
            return Json(data);
        }
        //添加职员
        public JsonResult addStaff(string user, Staff s)
        {
            bool data = SqlDbHelper.addStaff(user, s);
            return Json(data);
        }
        //根据编号查
        public JsonResult getStaffById(string ID)
        {
            List<Staff> data = SqlDbHelper.getStaffById(ID);
            return Json(data);
        }
        //根据姓名查
        public JsonResult getStaffByName(string name)
        {
            Staff data = SqlDbHelper.getStaffByName(name);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        //根据编号更新个人信息
        public JsonResult upSatff(string user, Staff s)
        {
            bool data = SqlDbHelper.upSatff(user, s);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        //根据id删除
        public JsonResult deleteById(string username, int id)
        {
            bool a = SqlDbHelper.deleteById(username, id);
            if (a)
                return getAllStaff();
            return Json(a);
        }
        //添加一个能登录的用户
        public ActionResult insertU(string username, string password, string admin)
        {
            int a = SqlDbHelper.insertUser(username, password, admin);
            if (a == 1)
                return Json("新增成功");
            return Json("新增失败");
        }

        //id升序
        public JsonResult getAllStaffInfoByIdasc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByIdUp();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        //id降序
        public JsonResult getAllStaffInfoByIddesc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByIdDesc();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        //name升序
        public JsonResult getAllStaffInfoByNameasc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByNameUp();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        //name降序
        public JsonResult getAllStaffInfoByNamedesc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByNameDesc();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        //standing升序
        public JsonResult getAllStaffInfoByStandingasc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByStandingUp();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        //standing降序
        public JsonResult getAllStaffInfoByStandingdesc()
        {
            List<Staff> data = SqlDbHelper.FindUsersByStandingDesc();
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        
    }
}